﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Hxsoft.AppV1.Module;

namespace Hxsoft.AppV1.WebUI
{
	public class SpecialList : BaseRepeaterList
	{
		private LoadedValue<string> loadedClassCode;
		/// <summary>
		/// 列表的类别代码。
		/// </summary>
		public virtual string ClassCode
		{
			get
			{
				if (loadedClassCode.Loader == null)
					loadedClassCode.Loader = () => (string)ViewState["ClassCode"];
				return loadedClassCode.Value;
			}
			set
			{
				if (loadedClassCode.Setter == null)
					loadedClassCode.Setter = v => ViewState["ClassCode"] = v;
				loadedClassCode.Value = value;
			}
		}

		private LoadedValue<int?> loadedChannelId;
		public  virtual int? ChannelId
		{
			get {
				if (loadedChannelId.Loader == null)
					loadedChannelId.Loader = () => (int?)ViewState["ChannelId"];
				return loadedChannelId.Value;
			}
			set {
				if (loadedChannelId.Setter == null)
					loadedChannelId.Setter = v => ViewState["ChannelId"] = v;
				loadedChannelId.Value = value;
			}
		}

		private LoadedValue<string> loadedKeyword;
		public virtual string Keyword
		{
			get
			{
				if (loadedKeyword.Loader == null)
					loadedKeyword.Loader = () => (string)ViewState["Keyword"];
				return loadedKeyword.Value;
			}
			set
			{
				if (loadedKeyword.Setter == null)
					loadedKeyword.Setter = v => ViewState["Keyword"] = v;
				loadedKeyword.Value = value;
			}
		}



		public override string ItemImageResourceCopyName
		{
			get
			{
				return string.IsNullOrEmpty(base.ItemImageResourceCopyName) ? GenericCommon.InfoResourceCopyName_SpecialList : base.ItemImageResourceCopyName;
			}
			set
			{
				base.ItemImageResourceCopyName = value;
			}
		}

		public virtual string ItemSpecialImageUrl
		{
			get
			{
				return ItemImageUrl;
			}
		}

		public virtual string ItemSpecialImageTag
		{
			get
			{
				return ItemImageTag;
			}
		}




		public override string ListMoreUrl
		{
			get
			{
				return GenericUrlManager.BuildSpecialListUrl(null);
			}
		}

		public override string TitleField
		{
			get { return "Title"; }
		}

		public override string ImageResourceField
		{
			get
			{
				return "Image";
			}
		}

		public override string DateTimeField
		{
			get
			{
				return "ReleaseDate";
			}
		}

		public override string ItemUrl
		{
			get
			{
				string url = Eval("LinkUrl", null);
				if (!string.IsNullOrEmpty(url)) return url;
				return GenericUrlManager.BuildSpecialUrl(Eval("SpecialCode", null));
			}
		}

		public virtual string ItemViceTitle
		{
			get
			{
				return Eval("ViceTitle", null);
			}
		}

		public override object GetListData()
		{
			return Specials.GetBaseList(Sites.CurrentSiteId, ClassCode, Keyword, LoadCount);
		}
	}
}